package com.xiongwei.exceptionHandling.logging;

import com.xiongwei.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * SLF4J和Logback可以取代Commons Logging和Log4j
 */
public class Slf4jAndLogbackTest {

    private Logger logger = LoggerFactory.getLogger(getClass());

    public static void main(String[] args) {
        Slf4jAndLogbackTest st = new Slf4jAndLogbackTest();
        st.test();
        //st.logbackFeature();
        st.testException();
    }

    /**
     * 五个日志级别:
     * error > warn > info(默认) > debug > trace
     */
    public void test() {
        logger.trace("trace");
        logger.debug("debug level");
        logger.info("info level");
        logger.warn("warn level");
        logger.error("error level");
    }

//    public void logbackFeature() {
//        User u = new User();
//        u.setName("xw");
//        u.setScore(99);
//        logger.info("set score {} for Person {} ok.", u.getScore(), u.getName());
//    }

    public void testException() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("there is a error");
        }
    }
}
